package cn.shentianlan.controller;

import cn.shentianlan.domain.User;
import cn.shentianlan.email.EmailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class EmailController {

    @Autowired
    private EmailUtil emailUtil;

    @PostMapping(value = "/sendEmail.do")
    public void sendEmail(HttpServletRequest request){
        Double gd_dev_O2_data = Double.parseDouble(request.getParameter("gd_dev_O2_data"));
        Double gd_dev_H2S_data = Double.parseDouble(request.getParameter("gd_dev_H2S_data"));
        Double gd_dev_CH4_data = Double.parseDouble(request.getParameter("gd_dev_CH4_data"));
        String email = request.getParameter("email");
        String message = null;
        if (gd_dev_O2_data>=23){
            message = "氧气 ";
        }
        if (gd_dev_H2S_data>=10){
            if (message !=null){
                message = message+"硫化氢 ";
            }else {
                message = "硫化氢 ";
            }

        }
        if (gd_dev_CH4_data>=100){
            if (message !=null){
                message = message+"甲烷 ";
            }else {
                message = "甲烷 ";
            }
        }

        emailUtil.sendSimpleEmail(email,"警告",message+"含量超标，请前去处理！");


    }
}
